helloApp.service('UserService', function ($http) {

    this.urlBase = "/api/user";

    this.getAll = function(callback) {
    	$http.get(this.urlBase+"/").success(callback);
    };

    this.getById = function(id, callback) {
    	$http.get(this.urlBase+"/"+id).success(callback);
    };

    this.save = function(object, callback) {
        //object.image = null;
        console.log(object);
    	$http({
            method: "POST",
            url: this.urlBase+"/",
            data: angular.toJson(object)
        }).success(callback);
    };

    this.update = function(object, callback) {
    	$http({
    		method: "PUT",
    		url: this.urlBase+"/"+object.id,
    		data: angular.toJson(object)
    	}).success(callback);
    };

    this.delete = function(id, callback) {
    	$http.delete(this.urlBase+"/"+id).success(callback);
    };

    this.uploadImage = function(file, callback) {

    	$http({
    		method: "POST",
    		url: this.urlBase+"/uploadImage",
            headers: { 'Content-Type': 'multipart/*'},
            transformRequest: function() { },
            cache: false,
            contentType: false,
            processData: false,
            //transformRequest: function (data) { return $.param(data) },
    		data: file
    	}).success(callback);
    };
});

